unit Con_Instruc;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,
  Db, DbTables, TFlatButtonUnit;

type
  TFrmCon_Instruc = class(TFrmConsulta)
    EdtNome: TEdit;
    dbgInstrucao: TDBGrid;
    Label1: TLabel;
    procedure BtnFecharClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure EdtNomeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Inst_Codigo: string;
    Inst_Descricao: string;
  end;

var
  FrmCon_Instruc: TFrmCon_Instruc;

implementation

uses Dm, Biblio, clsInstrucao;
{$R *.DFM}

var
  Instrucao: TInstrucao;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_Instruc.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Inst_codigo := tq.fieldbyname('Inst_Codigo').asstring;
  Inst_descricao := tq.fieldbyname('Inst_Descricao').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_Instruc.FormActivate(Sender: TObject);
begin
  inherited;
  tds := TDataSource.create(FrmCon_Instruc);
  tq := Tquery.create(FrmCon_Instruc);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  tds.DataSet := tq;
  fazconsulta;
  edtnome.setfocus;
end;

procedure TFrmCon_Instruc.EdtNomeKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    edtNome.setfocus;
  end;
end;

procedure TfrmCon_Instruc.FazConsulta;
begin
  if edtnome.text = '' then
    edtnome.text := ' ';
  Instrucao := TInstrucao.Create;
  Instrucao.Consultar(tq, edtnome.text);
  tq.open;
  Instrucao.free;
  dbgInstrucao.DataSource := tds;
  dbgInstrucao.Refresh;
end;

end.
